﻿using Microsoft.Data.SqlClient;
using System;
using System.Data;

namespace AuthCenter.Data
{
    public class MssqlRepo : IRepo
    {
        IDbConnection db { get; set; }
        public MssqlRepo(string connectionString)
        {
            db = new SqlConnection(connectionString);

        }

        internal bool ClosedState { get { return db.State == ConnectionState.Closed; } }

        public virtual IDbConnection Connection { get { return db; } }
        public virtual void Open()
        {
            if (ClosedState) db.Open();
        }
        public virtual void Close()
        {
            if (!ClosedState) db.Close();
        }

        public void Dispose()
        {
            Close();
        }
    }
}
